package com.joker.microstoremanager.controller;

import com.joker.microstoremanager.context.MessageHolder;
import com.joker.microstoremanager.model.MicroShop;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

@RestController
@RequestMapping("msg")
public class MessagerController {

    @RequestMapping("get")
    public DeferredResult<String> getMsg(){
        DeferredResult<String> result = new DeferredResult<>(30000L, "timeout");
        MicroShop user = (MicroShop) SecurityContextHolder.getContext()
                .getAuthentication()
                .getPrincipal();
        MessageHolder.holder.put(user.getId(),result);
        return result;
    }
}
